// pages/my/myInfo_order/myInfo_order.js
const API = require('../../../API/api.js');
const app = getApp();
Page({
    onChange(e) {
        console.log(e);
        if (e.detail.index == 0) {
            this.setData({
                status: '',
                orderList: [],
                pageNo: 0
            })
            this.getOrderList();
        } else if (e.detail.index == 1) {
            this.setData({
                status: 1,
                orderList: [],
                pageNo: 0
            })
            this.getOrderList();
        } else if (e.detail.index == 2) {
            this.setData({
                status: 2,
                orderList: [],
                pageNo: 0
            })
            this.getOrderList()
        } else {
            this.setData({
                status: 4,
                orderList: [],
                pageNo: 0
            })
            this.getOrderList()
        }
    },
    gotoOderInfo(e) {
        var orderId = e.currentTarget.dataset.orderid;
        wx.navigateTo({
            url: '../myInfo_order_info/myInfo_order_info?orderId=' + orderId
        })
    },
    getOrderList: function () {
        this.setData({
            flag: false
        })
        API.getOrderList({
            pageNo: this.data.pageNo,
            userId: wx.getStorageSync('userId'),
            status: this.data.status
        }).then((res) => {
            if (res.data.length < 10) {
                var f = false;
            } else {
                var f = true;
            }
            var pageNo = ++this.data.pageNo;
            console.log(res);
            var list = this.data.orderList.concat(res.data)
            this.setData({
                orderList: list,
                pageNo: pageNo,
                flag: f
            })
        })
    },
    /**
     * 页面的初始数据
     */
    data: {
        Height: 0,
        pageNo: 0,
        orderList: [],
        flag: true,
        imgUrl: app.globalData.imgUrl,
        status: ''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let that = this;
        wx.getSystemInfo({
            success: function (res) {
                that.setData({
                    Height: res.windowHeight * 2
                })
            },
        })
        that.getOrderList()
        console.log(that.data.flag)
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        if (this.data.flag) {
            wx.showLoading({
                title: '加载中...',
            })
            this.getOrderList();
        }
        setTimeout(function () {
            wx.hideLoading()
        }, 100)
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})
